<?php

namespace App\Admin\Controllers;

use App\Models\PickupCheckHistory;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class PickupCheckHistoryController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('核销历史');
            $content->description('列表');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
//    public function edit($id)
//    {
//        return Admin::content(function (Content $content) use ($id) {
//
//            $content->header('核销历史');
//            $content->description('修改');
//
//            $content->body($this->form()->edit($id));
//        });
//    }

    /**
     * Create interface.
     *
     * @return Content
     */
//    public function create()
//    {
//        return Admin::content(function (Content $content) {
//
//            $content->header('核销历史');
//            $content->description('新增');
//
//            $content->body($this->form());
//        });
//    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(PickupCheckHistory::class, function (Grid $grid) {

            $grid->model()->orderBy('id', 'DESC');
            $grid->id('ID')->sortable();
            $grid->pickupSite()->name('所属提货点');
            $grid->user()->mobile('核销人员手机号');
            $grid->shoppingOrder()->order_no('订单号');
            $grid->check_time('核销时间')->display(function ($time) {
                return date("Y-m-d H:i:s", $time);
            });


            $grid->disableCreateButton();
            $grid->disableExport();

            $grid->actions(function (Grid\Displayers\Actions $actions) {
                $actions->disableDelete();
                $actions->disableEdit();
            });

            $grid->tools(function (Grid\Tools $tools) {
                $tools->batch(function (Grid\Tools\BatchActions $actions) {
                    $actions->disableDelete();
                });
            });

            $grid->filter(function ($filter) {
                $filter->like('user.mobile', '用户手机')->mobile();
                $filter->equal('status', '状态')->select(['1' => '未支付', '2' => '未领取', '3' => '已领取', '4' => '已关闭', '5' => '已过期', '6' => '申请退款中', '7' => '已退款']); //订单状态：1.未支付（下单未支付），2.未领取（已支付未领取状态）3.已领取（完成状态），4.已关闭（超过24小时未支付订单或取消订单），5.已过期（新鲜实物未在规定时间领取），6申请退款 7已退款
            });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
//    protected function form()
//    {
//        return Admin::form(PickupCheckHistory::class, function (Form $form) {
//
//            $form->display('id', 'ID');
//
//            $form->display('created_at', 'Created At');
//            $form->display('updated_at', 'Updated At');
//        });
//    }
}
